package engine.newUi
{
	import engine.control.TurnPapersViewGroup;
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.View;
	import engine.data.ViewObject;
	import engine.flag.ResourcesPath;
	import engine.logic.DoubleClickManager;
	import engine.logic.event.LogicEvent;
	import engine.net.event.CustomMsgEvent;
	import engine.net.messages.CustomToClientFlag;
	import engine.net.messages.CustomToServerFlag;
	import engine.net.mgr.SystemSender;
	import engine.scene.SceneManager;
	import engine.tip.TipsMainLogic;
	import engine.ui.AlertUI;
	import engine.ui.UIManage;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	
	import newx.BaseObject;
	import newx.StageInfo;
	import newx.com.config.StaticIni;
	import newx.com.control.NxClip;
	import newx.com.control.group.NxViewGroup;
	import newx.com.control.text.NxLabel;
	import newx.com.control.window.NxWindowEvent;
	import newx.utils.MemoryOptimise;
	import newx.utils.MouseHandle;

	/**
	 * 商店逻辑 
	 * @author liuel
	 * 
	 */	
	public class SellLogic
	{
		/**
		 * 0,
		 * 1,白
		 * 2.绿
		 * 3.蓝
		 * 4.紫红
		 * 5.橙黄
		 * 6.黄
		 * 7.浅黄
		 */		
		protected const COLOR_TABLE	:Array	=	["","#ffffff'>","#1eff00'>","#20BFF8'>","#a335ee'>","#E8912E'>","#e5cc80'>","#ffff00'>"];
		private static var _self			:SellLogic;
		public var ui						:SellUI;
		private var _packui				:PackUI;
		/**数据模型*/
		private var _model					:ModelLocator;	
		private var _bind					:BindManage;
		private var _bindCastlePoint		:int    =	            -1;
		/**所有商品cionfigID**/
		private var _itemList				:Array  =	            [];	
		/**赎回物品数组**/
		private var _redeemArr				:Array  =               [];
		private var _typeTab				:int    =               1;
		private var _itemMC				:MovieClip
		private var _img					:NxClip;
		private var _txtCount				:NxLabel;
		
		private var  _txt1					:NxLabel;
		private var  _txt2					:NxLabel;
		private var _isSend				:Boolean =               false;
		/**第一次点击时间**/
		private var _fristTime				:int;
		/**翻页**/		
		private var _tableListener			:TurnPapersViewGroup;
		private var _time					:Timer;
		private var  _mc					:MovieClip;
		private var _overMc				:MovieClip;
		private var _clickMc				:MovieClip;
		private var _mouse					:MouseHandle;
		
		private var _doubleClick			:DoubleClickManager;
		//拖动的图片
		private var _dragmc:NxClip;
		
		private var  dragItem:Object;
		/**
		 * Group状态
		 * BASIV_STATE	普通状态
		 * ROLL_STATE   滑动状态
		 * CLICK_STATE  点击状态
		 * DISUSE_STATE 不能用状态
		 */		
		private const BASIV_STATE			:int	= 1;
		private const 	ROLL_STATE          :int	= 2;
		private const 	CLICK_STATE         :int	= 3;
		private const 	DISUSE_STATE		:int	= 4;
		public static function getInstance():SellLogic
		{
			if(_self == null)
			{
				_self = new SellLogic();
				
			}
			return _self;
		}
		public function SellLogic()
		{
		}
		public function Init():void
		{
		   ui               = SellUI.getInstance();
		   _packui          =PackLogic.getInstance().ui;
		   initInfo();
		   _tableListener    = new  TurnPapersViewGroup(ui.imgGroup,ui.btnPre,ui.btnNext,showItem,removeItem,afterShowItem,ui.pagelabel);
		   _model           = ModelLocator.getInstance(); 
		   _bind            = BindManage.getInstance();
		   _model.addEventListener(String(CustomToClientFlag.SERVER_CUSTOMMSG_OPEN_TRADE_WINDOW),onOpenTrade);
		  _mouse	= MouseHandle.getInstance();
		   _doubleClick		= DoubleClickManager.getInstance();
		   _doubleClick.addDoubleClick(SellLogic,clikFunction,doubleClickFunction);
		}
		public function BeforeShow():void
		{
			if(!SceneManager._itemIconLoad)
			{
				_model.addEventListener(LogicEvent.ITEMICONLOADED,loaded);
				function loaded():void
				{
					BeforeShow();
					_model.removeEventListener(LogicEvent.ITEMICONLOADED,loaded)
				}
			}
			_typeTab=1;
			ui.typeTab.selected=0;
			bind();
			showTypeShow();
			addEvent();
		}
		public function AfterHide():void
		{
//			SystemSender.getInstance().CustomMsg(CustomToServerFlag.CLIENT_CUSTOMMSG_REQUEST_CLOSE_UI,5);
			removeEvent();
			unBind();
		}
		
		private function bind():void
		{
			if(_bindCastlePoint == -1)
			{
				_bindCastlePoint = _bind.BindView(_model.scene,View.VIEWPORT_REDEEM,onDePositItem,onTakeItem);
			}
		}
		private function unBind():void
		{
			if(_bindCastlePoint != -1)
			{
				_bindCastlePoint = _bind.UnbindView(View.VIEWPORT_REDEEM,_bindCastlePoint);
			}
		}
		private function addEvent():void
		{
			ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			ui.typeTab.addEventListener(MouseEvent.CLICK,onSetList);
			ui.imgGroup.addItemsEvent(MouseEvent.MOUSE_OUT,onItemOut);
			ui.imgGroup.addItemsEvent(MouseEvent.MOUSE_OVER,onItemOver);
			ui.redeemGroup.addItemsEvent(MouseEvent.MOUSE_OUT,onItemOut);
			ui.redeemGroup.addItemsEvent(MouseEvent.MOUSE_OVER,onItemOver);
			ui.redeemGroup.addItemsEvent(MouseEvent.CLICK,onClickGroup);
			ui.imgGroup.addItemsEvent(MouseEvent.CLICK,onClickGroup);
			//背包中点击出售监听
			ui.addEventListener("clicksale",onClickSale);
			_tableListener.addListener();
		}
		private function removeEvent():void
		{
			ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,onClickClose);
			ui.typeTab.removeEventListener(MouseEvent.CLICK,onSetList);
			ui.imgGroup.removeItemsEvent(MouseEvent.ROLL_OUT,onItemOut);
			ui.imgGroup.removeItemsEvent(MouseEvent.ROLL_OVER,onItemOver);
			ui.redeemGroup.removeItemsEvent(MouseEvent.ROLL_OUT,onItemOut);
			ui.redeemGroup.removeItemsEvent(MouseEvent.ROLL_OVER,onItemOver)
				
			ui.redeemGroup.removeItemsEvent(MouseEvent.CLICK,onClickGroup);
			ui.imgGroup.removeItemsEvent(MouseEvent.CLICK,onClickGroup);
			_tableListener.removeListener();
		}
		private function initInfo():void
		{
			ui.typeTab.seletedLabelColor= 0xc5ffdc;
			ui.typeTab.defaultLabelColor= 0x648a7a;
			ui.typeTab.clearItems();
			ui.typeTab.addItem(StaticIni.getSwfLangStr("UIString_1000002"));
			ui.typeTab.addItem(StaticIni.getSwfLangStr("UIString_1000003"));
			initGroup(ui.imgGroup);
			initGroup(ui.redeemGroup);
			
		}
		private function initGroup(group:NxViewGroup):void
		{
		
			for (var i : int = 0; i <  group.row*group.col; i++)
			{
				_txt1	= 	new NxLabel();
				_txt2	=	new NxLabel();
				_itemMC	=	group.getItemByIndex(i);
				MemoryOptimise.stopMovie(_itemMC);
				_img		=	new NxClip(); 
				_img.x = _itemMC["img2"].x;
				_img.y = _itemMC["img2"].y;
				_img.defaultImage   =	null;
				_img.isCache		=	true;
				_img.source         =   null;
				
				_itemMC["img"]     =   _img;
				_itemMC["titleTxt1"] = _txt1;
				_itemMC["titleTxt1"].x =_itemMC["titleTxt"].x;
				_itemMC["titleTxt1"].y =_itemMC["titleTxt"].y;
				_itemMC["infoTxt1"]  = _txt2;
				_itemMC["infoTxt1"].x =_itemMC["infoTxt"].x;
				_itemMC["infoTxt1"].y =_itemMC["infoTxt"].y;
				_itemMC["infoTxt"].text = _itemMC["titleTxt"].text ="";
				_itemMC.addChild(_txt1);
				_itemMC.addChild(_txt2);
				_itemMC.addChild(_img);
				if(group == ui.redeemGroup)
				{
					_txtCount   =	new NxLabel();
					_txtCount.glowColor =0x081f22;
					_txtCount.x = _itemMC["img2"].x;
					_txtCount.y = _itemMC["img2"].y;
					_itemMC["txtCount"] = _txtCount;
					_itemMC.addChild(_txtCount);
				}
				
			}
		}

		////////////////////////////////////////////买卖翻页回调////////////////////////////////////////////////////////
		
		/**
		 * 显示对象
		 * @param	mc
		 * @param	data
		 */
		public function showItem(mc:MovieClip,data:Object):void 
		{
			var itemObject:Object = StaticIni.getIniObj(data["ConfigID"]);
			(mc["img"]	as NxClip)	.source	=	data["Photo"];
			mc["titleTxt1"]		.htmlText 	=	link_color(data["NameID"],int(itemObject["Color"]));
			if(int(data["type"]) == 1) //钱
			{
				mc["infoTxt1"].htmlText 	=	link_color(data["gold"],0)+link_color(setShowGoldStr(int(data["type"]),int(data["kind"])),0);
			}
			else if(int(data["type"]) == 2) //玉牌
			{
				mc["infoTxt1"].htmlText 	=	link_color(setShowGoldStr(int(data["type"]),int(data["kind"]))+"x",0)
				+link_color(data["gold"],0)+"";
			}
			mc["data"]				=	data;
			mc.addEventListener(MouseEvent.MOUSE_DOWN,StarDrag);
		}
		/**
		 * 删除对象
		 * @param	mc
		 */
		public function removeItem(mc:MovieClip):void 
		{
			(mc["img"]	as NxClip)	.clear();
		    (mc["img"]	as NxClip)	.source	=	null;
			mc["titleTxt1"]		    .text 	=	"";
			mc["infoTxt1"] 		    .text 	=	"";
			mc["data"]						=	null;
			mc.removeEventListener(MouseEvent.MOUSE_DOWN,StarDrag);
		}
		/**
		 * 翻页后的操作
		 */
		public function afterShowItem():void
		{
			if( _clickMc != null )
			{
				_clickMc["dt_mc"].gotoAndStop(BASIV_STATE);
			}
		}
		////////////////////////////////////////////////////////////////////////////////////////////////////

		private function showTypeShow():void
		{
			ui.imgGroup          .visible          = false;
			ui.redeemGroup       .visible          = false;
			if(_typeTab == 1)
			{
				ui.imgGroup      .visible          = true;
                ui.btnPre        .visible          = true;
				ui.btnNext       .visible          = true;
				ui.pagelabel     .visible          = true;
				ui.pagemc        .visible          = true;
				ui.nxlabel.htmlText =StaticIni.getSwfLangStr("UIString_1000327");
			}
			else
			{
				ui.redeemGroup   .visible          = true;
                ui.btnPre        .visible          = false;
				ui.btnNext       .visible          = false;
				ui.pagelabel     .visible          = false;
				ui.pagemc        .visible          = false;
				ui.nxlabel.htmlText =StaticIni.getSwfLangStr("UIString_1000328");
			}
		
		}
	
		////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 添加物品 
		 * 
		 */		
		private function onDePositItem(propertiesName:String,propertiesValue:ViewObject,data:*):void
		{
		
			updataItemImage(propertiesValue,true);
		}
		/**
		 * 购回物品
		 * 
		 */		
		private function onTakeItem(propertiesName:String,propertiesValue:ViewObject,data:*):void
		{
			updataItemImage(propertiesValue,false);
		}
		/**
		 * 赎回更新图片显示 
		 * @param oper true 存 false 取
		 * @param itemObject
		 * 
		 */
		private function updataItemImage(itemObject:ViewObject,oper:Boolean):void
		{
			//道具位置
			var itemPos:int = uint(itemObject.ObjKey);
			if(oper == true)
			{
				addItemImage(itemObject,itemPos)
			}
			else
			{
				removeItemImage(itemObject,itemPos);
			}
	
		}
		
		/**
		 * 赎回添加道具图片
		 */
		private function addItemImage(itemObject:ViewObject,itemPos:int):void
		{
			var index:int = itemPos 
			_itemMC = ui.redeemGroup.getItemByIndex(index - 1);
			
			_img=_itemMC["img"] ; 
			_img.source =ResourcesPath.getPropsURL(itemObject.GetProperties("Photo"));
			
			if(_img.parent==null)
			{
				_itemMC.addChild(_img);
			}
			var name:String=StaticIni.getSwfLangStr(itemObject.GetPropertiesEx("NameID"));
			var color:String =itemObject.GetProperties("Color");
			_itemMC["titleTxt1"].htmlText  =link_color(name,int(color)); 
			_itemMC["infoTxt1"] .htmlText  = link_color(itemObject.GetPropertiesEx("SellValue")+StaticIni.getSwfLangStr("CapitalType_0"),0);
				
			//当时有数量的物品时，显示物品
			if(itemObject.CheckProperties("Amount"))
			{
				_txtCount	=	_itemMC["txtCount"]; 
				_txtCount.htmlStr = itemObject.GetPropertiesEx("Amount");
				//绑定数量
				var amountIndex:int	 = _bind.BindProp(itemObject,"Amount",_itemMC["txtCount"],"htmlStrByBorder");
				_itemMC["amountIndex"] = amountIndex;
			}
			else
			{
				_txtCount	=	_itemMC["txtCount"]; 
				_txtCount .htmlText = "";
			}
			_itemMC["data"]	= itemObject;
			
			_itemMC.addEventListener(MouseEvent.MOUSE_DOWN,StarDrag);
		}
		private function onClickGroup(e:MouseEvent):void
		{
			_doubleClick.onClick(SellLogic,e);
		}
		private function clikFunction(e:MouseEvent):void
		{
			
		}
		private function doubleClickFunction(e:MouseEvent):void
		{
			_itemMC = e.currentTarget as MovieClip;
			var dateils:Object	=	e.currentTarget.data;
			if(dateils ==null)
				return;
			//点击的是买卖栏
			if(e.currentTarget.parent == ui.imgGroup)
			{
				var itemName:String = StaticIni.getSwfLangStr(dateils["NameID"]);
				//双击击购买一个
				SystemSender.getInstance().CustomMsg(
					CustomToServerFlag.CLIENT_CUSTOMMSG_TRADE_WITHNPC,0,View.VIEWPORT_TOOL,dateils["ConfigID"],-1,1);
			}
				//点击的是赎回栏
			else
			{
				//是装备只能赎回一个
				if(dateils.CheckProperties("Amount")==false)	
				{
					SystemSender.getInstance().CustomMsg(
						CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,dateils.GetPropertiesEx("ConfigID"),int(dateils.ObjKey),1);
				}
				else
				{
					//不是装备 赎回全部
						SystemSender.getInstance().CustomMsg(
							CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,dateils.GetPropertiesEx("ConfigID"),int(dateils.ObjKey),int(dateils.GetPropertiesEx("Amount")));
				}
//				var name:String=StaticIni.getSwfLangStr(dateils.GetPropertiesEx("NameID"));  
//					//双赎回一个
//					var index:int      = dateils.ObjKey;
//					var cionfigID:int  = dateils.GetPropertiesEx("ConfigID");
//					SystemSender.getInstance().CustomMsg(
//						CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,cionfigID,index,1);
			}
		}
		private function StarDrag(e:MouseEvent):void
		{
			var mc:MovieClip=e.currentTarget as MovieClip;
			if(mc && mc["img"].content)
			{
				_mouse.setItem(mc,mc["img"].content,true,mc["data"]);
//				StageInfo.stage.addEventListener(MouseEvent.MOUSE_UP,  StopDrag);
				_packui.group.addItemsEvent(MouseEvent.MOUSE_UP,  fun);
				_packui.group.addItemsEvent(MouseEvent.MOUSE_DOWN,  downfun);
				UIManage.getInstance().maskEnable=false
			}  
		}
		private function downfun(e:MouseEvent):void
		{
			_mouse.removeDrag();
		}
		private function fun(e:MouseEvent):void
		{
			var mc:MovieClip = e.currentTarget as MovieClip;
			var i:int = _packui.group.getChildIndex(mc);
			_packui.group.removeItemsEvent(MouseEvent.MOUSE_UP,  fun);
			var dateils:Object	=	_mouse.targetData;
			if(dateils == null) return;
			var configIDT:int=0;
			if(_typeTab ==1)
			{
				configIDT=dateils["ConfigID"];
			}
			else
			{
				configIDT=dateils.GetPropertiesEx("ConfigID");
			}
			//拖动的物品
			var dragItem:Object=StaticIni.getIniObj(String(configIDT));
			if(dragItem == null)
				return;
			
			var itemName:String = StaticIni.getSwfLangStr(dragItem["NameID"]);
			if(_typeTab==1)
			{
				//拖动购买多个
				AlertUI.showAlert(StaticIni.getSwfLangStr("SellUI_Buy"),StaticIni.getSwfLangStrVar("UIString_1000004",[" "+itemName+" "]),AlertUI.YES|AlertUI.NO,sendBuy,[_mouse.targetData],true,300,150,"1","0-9");
			}
			else
			{
				//是装备只能赎回一个
				if(dragItem["EquipType"]!=null)	
				{
					SystemSender.getInstance().CustomMsg(
						CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,configIDT,int(_mouse.targetData.ObjKey),1);
				}
				else
				{
					//不是装备 赎回全部
					if(dragItem["Amount"]!=null)
					{
						SystemSender.getInstance().CustomMsg(
							CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,configIDT,int(_mouse.targetData.ObjKey),int(_mouse.targetData.GetPropertiesEx("Amount")));
					}
				}
			}
			_mouse.removeDrag();
//			trace("购买存放的位置：",i+1);
		}
		private function StopDrag(e:MouseEvent):void
		{
			_packui.group.removeItemsEvent(MouseEvent.MOUSE_UP,  fun);
			StageInfo.stage.removeEventListener(MouseEvent.MOUSE_UP,  StopDrag);
		}

		protected function link_color(str:String,color:int):String
		{
			if(color < 1 || color >8)
			{
				color	=	1;
			}
			return ("<font color ='"+COLOR_TABLE[color]+str+"</font>");
		}
		/**
		 * 赎回删除道具图片
		 */
		private function removeItemImage(itemObject:ViewObject,itemPos:int):void
		{
			var index:int = itemPos 
			_itemMC=	ui.redeemGroup.getItemByIndex(index - 1);	
		    (_itemMC["img"]as NxClip).source="";

			//清除绑定
			if(_itemMC["amountIndex"]!=null){
				_bind.UnbindProp(_itemMC.data,"Amount",int(_itemMC["amountIndex"]));
			}
			_itemMC["titleTxt1"].text  ="";
			_itemMC["infoTxt1"] .text  ="";
			_itemMC["txtCount"].text  ="";
			_itemMC["data"] = null;
			_itemMC["txt"]	=	null;
			_itemMC["amountIndex"]	=null;
			_itemMC["dt_mc"].gotoAndStop(BASIV_STATE);
		}
		
		/**
		 * 确定购买 
		 * @param targetName
		 * @param inputTxt
		 * @param data
		 * 
		 */		
		private function sendBuy(targetName:int,inputTxt:String,data:Array):void
		{
			if(targetName	==	AlertUI.YES)
			{
				var objData:Object	=	data[0];
				var amount:uint		=	1;
				if(inputTxt!=""&&inputTxt!=null)
				{
					amount	=	int(inputTxt);
				}
				
				SystemSender.getInstance().CustomMsg(
					CustomToServerFlag.CLIENT_CUSTOMMSG_TRADE_WITHNPC,0,View.VIEWPORT_TOOL,objData["ConfigID"],-1,amount);

			}
		}
		/**
		 * 确定赎回 
		 * @param targetName
		 * @param inputTxt
		 * @param data
		 * 
		 */		
		private function sendRemeed(targetName:int,inputTxt:String,data:Array):void
		{
			if(targetName	==	AlertUI.YES)
			{
				var objData:Object	=	data[0];
				var index:int      = objData.ObjKey;
				var cionfigID:int  =objData.GetPropertiesEx("ConfigID");
				var amount:uint		=	1;
				if(inputTxt!=""&&inputTxt!=null)
				{
					amount	=	int(inputTxt);
				}
				
				SystemSender.getInstance().CustomMsg(
					CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,cionfigID,index,amount);
			}
		}
		/**
		 * 打开商店和仓库 
		 * 
		 */		
		private function openSellMoive():void
		{
			if(ui.created == false)
			{
				ui.showOrHide();
			}
			if(_packui.created == false)
			{
				_packui.showOrHide();
			}
			
		}
		/**
		 * 播放打开仓库和商店效果
		 * @param e
		 * 
		 */		
		private function onPlay(e:TimerEvent):void
		{
			var speed:Number = _packui.windowBG.width/2/_time.repeatCount;
			ui.windowBG.x-=speed;
			_packui.windowBG.x+=speed;
			if(_time.currentCount == _time.repeatCount)
			{
				_time.reset();
			}
			
		}
		////////////////////////////////////////////////////////侦听函数//////////////////////////////////////////////////////////////////
		/**
		 * 背包中点击出售 
		 * @param e
		 * 
		 */	    
		private function onClickSale(e:Event):void
		{
			_typeTab =2;
			ui.typeTab.selected=1
			showTypeShow();
			
		}
		
		/**
		 * 打开商店 接受数据
		 * @param e
		 * 
		 */		
		private function onOpenTrade(e:CustomMsgEvent):void
		{
			_itemList=[];
			var pList : Array = e.pList;
			openSellMoive();
			_tableListener.clear();
			
			var obj:Object;
			var itemObj:Object;
			for (var i:int=0;i<pList.length;i+=4)
			{
				obj 	= new Object();
				                      
 				itemObj = StaticIni.getIniObj(pList[i]);
				obj["ConfigID"]  	= pList[i];
				obj["type"]			= pList[i+1]; //类型  1 钱 2玉牌
				obj["kind"]			= pList[i+2]; //种类  
				obj["Photo"]       = ResourcesPath.getPropsURL(itemObj["Photo"]);
				obj["gold"]        = pList[i+3];
				obj["NameID"]      = StaticIni.getSwfLangStr(itemObj["NameID"]);
				
				_itemList.push(obj);
			}
			_tableListener.dataProvider	=_itemList;
			
		}
		private function setShowGoldStr(type:int,kind:int):String
		{
			var strID:String;
			if(type == 1) //钱
			{
				switch(kind)
				{
					case 0:  //铜钱
						strID ="UIString_1000240"
						break;
					case 1: //阅历
						strID ="UIString_1000241"
						break;
					case 2:  //江湖声望
						strID ="UIString_1000242"
						break;
					case 3:  //修为
						strID ="UIString_1000243"
						break;
					case 4: //元宝
						strID ="UIString_1000244"
						break;
				}
			}
			else if(type == 2) //玉牌
			{
				switch(kind)
				{
					case 0:
						strID ="未定义类型"
					case 1:   //白
						strID ="UIString_1000245"
						break;
					case 2:   //绿
						strID ="UIString_1000246"
						break;
					case 3: //蓝
						strID ="UIString_1000247"
						break;
					case 4:   //紫
						strID ="UIString_1000248"
						break;
					case 5:  //黄
						strID ="UIString_1000249"
						break;
				}
			}
			return StaticIni.getSwfLangStr(strID);
		}
		private function onClickClose(e:NxWindowEvent):void
		{
			ui.hide();
		}
		
		/**
		 * 点击Tab 
		 * @param e
		 * 
		 */		
		private function onSetList(e:MouseEvent):void
	   {
			_typeTab= ui.typeTab.selected+1;
		   showTypeShow();
	   }

//		private function onItemDown(e:MouseEvent):void
//		{
//			if(_mc)
//			{
//				_mc["dt_mc"].gotoAndStop(BASIV_STATE);
//			}
//			_itemMC = e.currentTarget as MovieClip;
//			
//			var dateils:Object	=	e.currentTarget.data;
//			if(dateils ==null)
//			{
//				
//				return;
//			}
//			_mc=_itemMC;
//			_itemMC["dt_mc"].gotoAndStop(CLICK_STATE);
//			_clickMc = _itemMC;
//			//点击的是买卖栏
//			if(e.currentTarget.parent == ui.imgGroup)
//			{
//				var itemName:String = StaticIni.getSwfLangStr(dateils["NameID"]);
//				if(getTimer()-_fristTime<250)
//				{    
//					//双击击购买一个
//					SystemSender.getInstance().CustomMsg(
//						CustomToServerFlag.CLIENT_CUSTOMMSG_TRADE_WITHNPC,0,View.VIEWPORT_TOOL,dateils["ConfigID"],-1,1);
//					return;
//				}
//
//			}
//			//点击的是赎回栏
//			else
//			{
//				var name:String=StaticIni.getSwfLangStr(dateils.GetPropertiesEx("NameID"));
//				if(getTimer()-_fristTime<250)
//				{    
//					//双赎回一个
//					var index:int      = dateils.ObjKey;
//					var cionfigID:int  = dateils.GetPropertiesEx("ConfigID");
//					SystemSender.getInstance().CustomMsg(
//						CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,cionfigID,index,1);
//					return;
//				}
//	
//			}
//			
//			_fristTime=getTimer();
//			_isSend=false;
//		
//			var mc:NxClip=_itemMC["img"];//e.target as NxClip;
//			if(mc)
//			{
//					
//				MouseHandle.getInstance().setMouseDrag(mc.content,true,dateils);
//				StageInfo.stage.addEventListener(MouseEvent.MOUSE_UP,  onItemUp);
//			}
//			
//		}
//		private function onItemUp(e:MouseEvent):void
//		{
//		
//			var obj:DisplayObject=PackLogic.getInstance().ui;
//			var dateils:Object	=	MouseHandle.getInstance().targetData;
//			var configIDT:int=0;
//			if(_typeTab ==1)
//			{
//				configIDT=dateils["ConfigID"];
//			}
//			else
//			{
//				configIDT=dateils.GetPropertiesEx("ConfigID");
//			}
//			//拖动的物品
//			var itembj:Object=StaticIni.getIniObj(String(configIDT));
//			if(obj.visible == true)
//			{
//				if(obj.hitTestPoint(StageInfo.stage.mouseX,StageInfo.stage.mouseY))
//				{
//					if(_isSend==true)
//					{
//						return;
//					}
//					_isSend=true;
//					var itemName:String = StaticIni.getSwfLangStr(itembj["NameID"]);
//					if(_typeTab==1)
//					{
//							//拖动购买多个
//						AlertUI.showAlert(StaticIni.getSwfLangStr("SellUI_Buy"),StaticIni.getSwfLangStrVar("UIString_1000004",[" "+itemName+" "]),AlertUI.YES|AlertUI.NO,sendBuy,[dateils],true,300,150,"1","0-9");
//					}
//					else
//					{
//						//是装备只能赎回一个
//						if(itembj["EquipType"]!=null)	
//						{
//								
//							SystemSender.getInstance().CustomMsg(
//									CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,configIDT,int(dateils.ObjKey),1);
//						}
//						else
//						{
//								//不是装备 赎回全部
//							if(itembj["Amount"]!=null)
//							{
//								SystemSender.getInstance().CustomMsg(
//									CustomToServerFlag.CLIENT_CUSTOMMSG_SUEEL_SEMEED,View.VIEWPORT_REDEEM,configIDT,int(dateils.ObjKey),int(dateils.GetPropertiesEx("Amount")));
//									
//							}
//								
//						}
//						
//					}
//					
//				}
//			}
//			MouseHandle.getInstance().removeDrag();
//			StageInfo.stage.removeEventListener(MouseEvent.MOUSE_DOWN,  onItemDown);
//			StageInfo.stage.removeEventListener(MouseEvent.MOUSE_UP,  onItemUp);
//		}

		/**
		 * 显示Tips 
		 * @param e
		 * 
		 */		
		private function onItemOver(e:MouseEvent):void
		{
			if( _overMc != null )
			{
				if(_overMc["dt_mc"].currentFrame != CLICK_STATE)
				{
					_overMc["dt_mc"].gotoAndStop(BASIV_STATE);
				}
			}
			_overMc	=	e.currentTarget as MovieClip;
			if(_overMc["dt_mc"].currentFrame != CLICK_STATE)
			{
				_overMc["dt_mc"].gotoAndStop(ROLL_STATE);
			}
			if(_typeTab ==1)
			{
			    var obj:Object= _overMc.data ;
				if(obj == null)
					return;
				var obb:Object=TipsMainLogic.instance.getStaticObjWithID(obj["ConfigID"]);
				obb["SellValue"]=obj["gold"];
				obb["_type"]= obj["type"];
				obb["_kind"]= obj["kind"];
				TipsMainLogic.instance.showMain(obb,true);
			}
			else
			{
				var itemObject:BaseObject = _overMc.data as BaseObject;
				if(itemObject != null && itemObject.CheckProperties("ConfigID"))
				{
					TipsMainLogic.instance.showMain(itemObject,true);
					
				}
			}
		}
		/**
		 * 关闭Tips
		 * @param e
		 * 
		 */		
		private function onItemOut(e:MouseEvent):void
		{
			_overMc = e.currentTarget as MovieClip;
			if(_overMc["dt_mc"].currentFrame != CLICK_STATE)
			{
				_overMc["dt_mc"].gotoAndStop(BASIV_STATE);
			}
			TipsMainLogic.instance.hide();
		}
	}
}